﻿<UserControl x:Class="TanmiaGrp.GeneralLedger.WinApp.Scenarios.GroupBrowserView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:loc="clr-namespace:TanmiaGrp.GeneralLedger.WinApp"
             xmlns:Scenarios="clr-namespace:TanmiaGrp.GeneralLedger.WinApp.Scenarios"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mui="http://firstfloorsoftware.com/ModernUI"
             mc:Ignorable="d"
             d:DesignHeight="300"
             d:DesignWidth="600"
             FlowDirection="RightToLeft"
             Background="Transparent"
             PreviewMouseDown="UserControl_PreviewMouseDown">
    <UserControl.Resources>
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
        <loc:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
    </UserControl.Resources>

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <Grid Name="searchBar" Grid.Column="0" Width="0">
            <Grid.Resources>
                <Style TargetType="{x:Type mui:ModernButton}">
                    <Setter Property="Width" Value="32" />
                    <Setter Property="Height" Value="32" />
                    <Setter Property="EllipseDiameter" Value="30" />
                    <Setter Property="Foreground" Value="#FFA1A1A1" />
                    <Setter Property="Margin" Value="2,0,0,0" />
                    <Setter Property="IconWidth" Value="12" />
                    <Setter Property="IconHeight" Value="12" />
                    <Setter Property="Background" Value="White" />
                    <Setter Property="BorderBrush" Value="#919191" />
                    <Setter Property="EllipseStrokeThickness" Value="2" />
                </Style>
            </Grid.Resources>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <DockPanel Grid.Row="0" Height="46">
                <TextBlock Text="البحث" Foreground="#FF6699C9" FontSize="22" VerticalAlignment="Center" Margin="4,0" />

                <!-- Close SearchPanel Button -->
                <mui:ModernButton ToolTip="خلف" FlowDirection="LeftToRight" IconData="{StaticResource Back}" HorizontalAlignment="Right" Margin="0,0,2,0">
                    <mui:ModernButton.Triggers>
                        <EventTrigger RoutedEvent="Button.Click">
                            <BeginStoryboard>
                                <Storyboard>
                                    <!-- Contract width of SearchBar -->
                                    <DoubleAnimation Storyboard.TargetName="searchBar"
                                                 Storyboard.TargetProperty="Width"
                                                 To="0"
                                                 Duration="0:0:.4" />
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                    </mui:ModernButton.Triggers>
                </mui:ModernButton>
            </DockPanel>

            <Grid Grid.Row="1">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <TextBox Name="txtSearch" 
                         Grid.Row="0"
                         Height="30" 
                         VerticalContentAlignment="Top" 
                         FontSize="16" 
                         Text="{Binding Path=SearchSpecification.InteractiveSearch, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Margin="4,2,4,0" />

                <CheckBox Grid.Row="1" 
                          Height="32" 
                          Foreground="Gray" 
                          Content="اظهار المجموعات الموقفة" 
                          Margin="4,0" 
                          VerticalAlignment="Top" 
                          IsChecked="{Binding Path=SearchSpecification.ShowIsDisabled, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"/>
            </Grid>

            <DockPanel Grid.Row="2" Height="46">
                <mui:ModernButton ToolTip="تحديث البيانات"
                                  IconData="{StaticResource Refresh}"
                                  HorizontalAlignment="Right"
                                  Margin="0,0,2,0"
                                  Command="{Binding Path=RefreshCommand}" 
                                  CommandParameter="{x:Static loc:NavigationMoveEnum.KeepCurrent}"/>
            </DockPanel>

            <!-- separator between panels -->
            <Border Grid.Row="0" Grid.RowSpan="2" Grid.Column="1" Width="1" Margin="2,0">
                <Border.Background>
                    <LinearGradientBrush StartPoint=".5,0" EndPoint=".5,1">
                        <GradientStop Color="#FFDADADA" Offset="0.0" />
                        <GradientStop Color="#919191" Offset=".8" />
                        <GradientStop Color="#919191" Offset=".2" />
                        <GradientStop Color="#FFE4E4E4" Offset="1.0" />
                    </LinearGradientBrush>
                </Border.Background>
                <Border.Effect>
                    <DropShadowEffect ShadowDepth="0" Direction="1" Opacity="0.395" Color="#FF919191"  />
                </Border.Effect>
            </Border>
        </Grid>

        <Grid Grid.Column="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="2" />
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <DockPanel Grid.Row="0" Height="46">
                <Scenarios:WindowBar x:Name="windowBar" PopouClicked="OnPopout" />
                <mui:ModernButton ToolTip="بحث" 
                                  IconData="{StaticResource Search}" 
                                  Width="32" Height="32" 
                                  EllipseDiameter="30" 
                                  EllipseStrokeThickness="2"
                                  Foreground="#FFA1A1A1" 
                                  Margin="2,0,0,0" 
                                  IconWidth="12" 
                                  IconHeight="12" 
                                  Background="White" 
                                  BorderBrush="#919191">
                    <mui:ModernButton.Triggers>
                        <EventTrigger RoutedEvent="Button.Click">
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="searchBar" 
                                                     Storyboard.TargetProperty="Width"
                                                     To="200"
                                                     Duration="0:0:.6" AccelerationRatio="1" />
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                    </mui:ModernButton.Triggers>
                </mui:ModernButton>

                <TextBlock DockPanel.Dock="Left" 
                           Text="المجموعات" 
                           Style="{StaticResource CaptionStyle}" />
                <Scenarios:AddBar HorizontalAlignment="Right" DockPanel.Dock="Right" />
                <Scenarios:SelectionModificationBar HorizontalAlignment="Right" Visibility="{Binding ElementName=dgGroups, Path=SelectedItem, Converter={StaticResource NullToVisibilityConverter}}" />
            </DockPanel>

            <ProgressBar Grid.Row="1" Minimum="0" Maximum="1" Height="2" IsIndeterminate="True" VerticalAlignment="Center" HorizontalAlignment="Stretch" 
                         Visibility="{Binding Path=EntitiesTask.IsNotCompleted, Converter={StaticResource BooleanToVisibilityConverter}}"/>

            <Border Grid.Row="2"  BorderBrush="#FF6699C9" BorderThickness="0">
                <DataGrid Name="dgGroups"
                          ItemsSource="{Binding Path=EntitiesTask.Result.Entities}"
                          CanUserAddRows="False"
                          CanUserDeleteRows="False"
                          CanUserResizeRows="False"
                          IsSynchronizedWithCurrentItem="True"
                          FontFamily="Tahoma"
                          AutoGenerateColumns="False" 
                          RowHeight="24">

                    <DataGrid.ItemContainerStyle>
                        <Style TargetType="DataGridRow">
                            <Setter Property="IsSelected"
                                Value="{Binding Path=IsSelected, Mode=TwoWay}" />
                        </Style>
                    </DataGrid.ItemContainerStyle>
                    <DataGrid.Columns>

                        <DataGridTextColumn Header="رقم المجموعة"
                                        Binding="{Binding Path=GroupID}"
                                        IsReadOnly="True" />

                        <DataGridTextColumn Header="اسم المجموعة"
                                        Binding="{Binding Path=GroupName}"
                                        IsReadOnly="True" />

                        <DataGridTextColumn Header="فعال؟"
                                        Binding="{Binding Path=IsEnabled}"
                                        IsReadOnly="True" />

                        <DataGridTextColumn Header="ملاحظات"
                                        Binding="{Binding Path=Notes}"
                                        IsReadOnly="True" />

                        <DataGridTextColumn Header="تاريخ الإنشاء"
                                            IsReadOnly="True">
                            <DataGridTextColumn.Binding>
                                <Binding Path="CreateDate"
                                         StringFormat="{x:Static loc:ConfigurationSettings.DateFormat}" />
                            </DataGridTextColumn.Binding>
                        </DataGridTextColumn>
                    </DataGrid.Columns>
                </DataGrid>
            </Border>

            <!--<Label Content="Loading..."
                   VerticalContentAlignment="Center"
                   HorizontalContentAlignment="Center"
                   Background="White"
                   Opacity=".7"
                   Visibility="{Binding Path=EntitiesTask.IsNotCompleted, Converter={StaticResource BooleanToVisibilityConverter}}" />-->

            <Grid Grid.Row="3" Height="46">
                <Scenarios:PageNavigationBar HorizontalAlignment="Right" />
            </Grid>
        </Grid>
    </Grid>
</UserControl>
